package eclipse;

import java.util.ArrayList;
import java.util.Scanner;




/*
names = ["A","B", "C"]
price = [23, 53, 52]
numbers = [100, 180, 28]
 */
public class ArrayExercise04 {
    static String[] names = {"iPhoneX","小米8","华为P20","vivo Find X","oppo Find N"};
    static double[] price = {8499, 2800, 4699, 3099, 7999};
    static int[] numbers = {200, 500, 600, 200, 100};
    public static void main(String[] args) {

        whole:
        while(true){
            showMenu();
            System.out.print("请输入一个数字:");
            int order = new Scanner(System.in).nextInt();
            switch (order){
                case 1: f1(); break;
                case 2: f2(); break;
                case 3: f3(); break;
                case 4: f4(); break;
                case 5: break whole;
            }
        }
    }

    private static void f4() {
        /*
        货物总价
        单价均价
        最高单价
        最高总价
         */
        System.out.println(sum(price));
        System.out.println(avg(price));
        System.out.println(top(price));
        System.out.println(get_total_price(price));
    }

    private static double get_total_price(double[] price) {
        double top = 0;
        for(int i = 0; i < price.length; i++){
            if(top < (price[i] * numbers[i])){
                top = price[i] * numbers[i];
            }
        }
        return top;
    }

    private static double top(double[] price) {
        double top = 0;
        for(int i = 0; i < price.length; i++){
            if (top < price[i]){
                top = price[i];
            }

        }
        return top;
    }

    private static double avg(double[] price) {
        return sum(price) / price.length;
    }

    private static double sum(double[] price) {
        int sum = 0;
        for(int i = 0; i < price.length; i++){
            sum += price[i];
        }
        return sum;
    }

    private static void f3() {
        System.out.print("请输入商品名称:");
        String name = new Scanner(System.in).nextLine();
        for(int i = 0; i < names.length; i++){
            if(names[i].equals(name)){
                System.out.println((i + 1)+"."+
                        "名称:"+names[i]+
                        " 价格:"+price[i]+
                        " 库存数量:"+numbers[i]);
            }
        }

    }

    private static void f2() {

    }

    private static void f1() {
        for(int i = 0; i < names.length; i++){
            System.out.println((i + 1)+"."+
                    "名称:"+names[i]+
                    " 价格:"+price[i]+
                    " 库存数量:"+numbers[i]);
        }
    }

    private static void showMenu() {
        System.out.println("-------------------------");
        System.out.println("1. 商品列表");
        System.out.println("2. 商品录入");
        System.out.println("3. 商品查询");
        System.out.println("4. 统计信息");
        System.out.println("5. 退出");
        System.out.println("-------------------------");
        System.out.print("选择:");
    }
}
